#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
# include "windows.h"



bool check_valid(int year, int month,int day)
{
	if (year < 0 || month < 0 || month >12||day<0)
	{
		return false;
	}
	if (month == 1&& month == 3 && month == 5 && month == 7 && month == 8 && month == 10 && month == 12 )
	{
		if (day > 31)
		{
			return false;
		}
	}
	if (month == 4 && month == 6 && month == 9 && month == 11)
	{
		if (day > 30)
		{
			return false;
		}
	}
	if (((year % 100 != 0) && 0 == year % 4) || (year % 400 == 0))
	{
		if (2 == month)
		{
			if (day > 29)
			{
				return false;
			}
		}
	}
	else
	{
		if (2 == month)
		{
			if (day > 28)
			{
				return false;
			}
		}
	}
	return true;
}

int zeller_func(int year, int month, int day)
{
	int c = year / 100;
	int y = year % 100;
	int m = month;
	int d = day;
	int result = 0;
	if (!check_valid(year,month,day))
	{
		return -1;
	}
	if (year <= 1582)
	{
		if (year < 1582)
		{
			result = y + (y / 4) + (c / 4) - (2 * c) + (13 * (m + 1) / 5) + d + 2;
			return result;
		}
		if (1582 == year)
		{
			if ((month == 10 && day < 4) || month < 10)
			{
				result = y + (y / 4) + (c / 4) - (2 * c) + (13 * (m + 1) / 5) + d + 2;
				return result;
			}
		}
	}
	else
	{
		result = ((c / 4) - 2 * c + y + (y / 4) + (13 * (m + 1) / 5) + d - 1) % 7;
		return result;
	}
	return -1;
}
typedef struct Date {
	int Y;
	int M;
	int D;
	void set_date(int y, int m, int d)
	{
		Y = y;
		M = m;
		D = d;
	}
}TDATE;

void show(int result , TDATE& pDate)
{
	std::string out;

	switch (pDate.M)
	{
	case 1:
		out.append("January ");
		break;
	case 2:
		out.append("February ");
		break;
	case 3:
		out.append("March ");
		break;
	case 4:
		out.append("April ");
		break;
	case 5:
		out.append("May ");
		break;
	case 6:
		out.append("June ");
		break;
	case 7:
		out.append("July ");
		break;
	case 8:
		out.append("Aguest ");
		break;
	case 9:
		out.append("September ");
		break;
	case 10:
		out.append("October ");
		break;
	case 11:
		out.append("November ");
		break;
	case 12:
		out.append("December ");
		break;
	default:
			break;
	}
	char cDay[3];
	char cYear[10];
	memset(cDay, '\0', 3);
	memset(cYear, '\0', 10);
	_itoa_s(pDate.D, cDay, 10);
	_itoa_s(pDate.Y, cYear, 10);
	out.append(cDay);
	out.append(",");
	out.append(cYear);
	out.append(" is a ");
	switch (result)
	{
	case 0:
		out.append("Sunday");
		break;
	case 1:
		out.append("Monday");
		break;
	case 2:
		out.append("Tusday");
		break;
	case 3:
		out.append("Wednesday");
		break;
	case 4:
		out.append("Thursday");
		break;
	case 5:
		out.append("Thursday");
		break;
	case 6:
		out.append("Saturday");
		break;
	default:
		out.clear();
		out.append("Date is invalid");
		break;
	}
	std::cout << out << std::endl;
}

int main(void)
{
	int y, m, d;
	int result;
	std::vector<TDATE> p_DateArr;
	std::vector<int> resultArr;
	while (1)
	{
		std::cin >> y >> m >> d;
		//std::cout << y << " " << m << " " << d << std::endl;
		TDATE pDate;
		if (0 == y && 0 == m && 0 == d)
		{
			break;
		}
		pDate.set_date(y, m, d);
		p_DateArr.push_back(pDate);
		std::cin.clear();
	}
	for (int i = 0; i < p_DateArr.size(); ++i)
	{
		result = zeller_func(p_DateArr[i].Y, p_DateArr[i].M, p_DateArr[i].D);
		show(result,p_DateArr[i]);
	}
	
	system("pause");
}